package com.manager.dao;

import com.manager.domain.Student;

public class StudentDao {
    Student[] stud = new Student[30];
    public boolean addStudent(Student stu) {
        for (int i = 0; i < stud.length; i++) {
            Student student = stud[i];
            if (student==null){
                stud[i] = stu;
                return true;
            }
        }
        return false;
    }

    public Student[] findAllStudent() {
        return stud;
    }

    public void delStudent(String id) {
        int index = getIndex(id);
        stud[index] = null;
    }

    private int getIndex(String id) {
        for (int i = 0; i < stud.length; i++) {
            Student student = stud[i];
            if (student!=null && student.getId().equals(id)){
                return i;
            }
        }
        return -1;
    }
    public void upDataStudent(Student student, String id) {
        int index = getIndex(id);
        stud[index] = student;
    }
}
